set_xmakever("2.8.5")
includes("@builtin/check")

add_includedirs("include")
add_includedirs("shmipc/include")
set_languages("c99")
set_languages("c++17")

set_configdir("$(buildir)/config")
add_configfiles("config.h.in")

configvar_check_links("HAS_POSIX_THREAD", {"pthread", "m", "dl"})
configvar_check_cfuncs("HAS_POSIX_MUTEX_API", 
{"pthread_mutex_init",
 "pthread_mutex_destroy", 
 "pthread_mutex_lock", 
 "pthread_mutex_unlock",
  "pthread_cond_init", 
  "pthread_cond_destroy", 
  "pthread_cond_signal",
  "pthread_cond_broadcast",
  "pthread_cond_wait",
  "pthread_cond_timedwait"
}, 
{includes = {"pthread.h"}})

configvar_check_cfuncs("HAS_POSIX_SHM", 
{"shm_open",
 "shm_unlink"
}, 
{includes = {"sys/mman.h"}})

configvar_check_cfuncs("HAS_LINUX_XTIME", 
{"clock_gettime"
}, 
{includes = {"sys/time.h"}})

configvar_check_cfuncs("HAS_POSIX_FILE_API", {"open", "close", "write", "read", "lseek", "fsync", "fstat"}, {includes = {"fcntl.h", "unistd.h", "sys/stat.h"}})
configvar_check_cfuncs("HAS_POSIX_DIR_API", {"opendir","closedir", "readdir", "rmdir", "mkdir", "access"}, {includes = {"dirent.h", "unistd.h", "sys/stat.h"}})
configvar_check_cfuncs("HAS_POSIX_DLL_API", {"dlopen", "dlclose", "dlsym", "dlerror"}, {includes = {"dlfcn.h"}})

configvar_check_cfuncs("HAS_STD_ATOMIC", 
{"atomic_fetch_add", 
"atomic_fetch_sub", 
"atomic_fetch_or", 
"atomic_fetch_and", 
"atomic_compare_exchange_strong"}, 
{includes = {"stdatomic.h"}})

configvar_check_cfuncs("HAS_WIN_THREAD", 
{"_beginthreadex", 
"SetThreadDescription", 
"SetThreadPriority", 
"GetThreadPriority", 
"GetCurrentThreadId",
"GetThreadId"}, 
{includes = {"process.h","windows.h"}})




add_includedirs("$(buildir)/config")

-- add rules: debug/release
add_rules("mode.debug", "mode.release")

--includes("src")
--add_subdirs("test")
includes("shmipc")
--target("hello_world")
--	set_kind("binary")
--  add_deps("cbus")
--  add_links("cbus"9)
--	add_files("./test/hello_world/*.c")

		   
		   